(function () {
    document.addEventListener('DOMContentLoaded', function () {
        var html = document.documentElement;
        var windowWidth = html.clientWidth;
        html.style.fontSize = windowWidth / 6.4 + 'px';  //设计稿横向宽度是640px
    }, false);
})();

$(function () {

    $('.select-input').each(function (i, el) {
        $(el).change(function () {
            var val = $(this).val();
            $(this).prev('.select-face').html(val);
        });
    });

    $('.tabs .box-hd .cell').on('touchend', function(){
        var idx = $(this).index();
        $(this).addClass('active').siblings().removeClass('active');
        $('.tabs .box-bd .bd-bd').hide();
        $('.tabs .box-bd .bd-bd').eq(idx).show();
    });

    $('.nav-tab .item').on('touchend',function(){
       $(this).addClass('active').siblings().removeClass('active');
    });
    $('.tabs-tabs nav ul li').on('click',function(){
        $(this).addClass('active').siblings().removeClass('active');
    });

});

/*商品数量框输入*/
function keyup(obj){
    var quantity = $(obj).val();
    if(isNaN(quantity) ||  parseInt(quantity)!=quantity || parseInt(quantity)<1){
        quantity = 1;
        return;
    }
    if(quantity>=20){
        $(obj).val(quantity.substring(0,quantity.length-1));
        alert("商品数量超出范围！");
    }
    $(obj).parents('.mui-number').find('.quantity_val').val(quantity);
}
/*商品数量+1*/
function numAdd(obj){
    var quantity = $(obj).prev(".quantity").val();
    var num_add = parseInt(quantity)+1;
    if(quantity==""){
        num_add = 1;
    }
    if(num_add>=20){
        $(obj).prev(".quantity").val(num_add-1);
        alert("商品数量超出范围！");
    }else{
        $(obj).prev(".quantity").val(num_add);
    }
    $(obj).parents('.mui-number').find('.quantity_val').val(num_add);
}
/*商品数量-1*/
function numDec(obj){
    var quantity = $(obj).next('.quantity').val();
    var num_dec = parseInt(quantity)-1;
    if(num_dec>0){
        $('.quantity').val(num_dec);
    }
    $(obj).parents('.mui-number').find('.quantity_val').val(num_dec);
}